'use strict'
const path = require('path')

function resolve(dir) {
    return path.join(__dirname, dir)
}

const CompressionPlugin = require("compression-webpack-plugin")

// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

const defaultSettings = require('./src/settings.js')

module.exports = {
    publicPath: '/',
    outputDir: 'dist',
    assetsDir: 'static',
    devServer: {
        port: 8082,
        proxy: {
            '/api': {
                target: 'http://202.107.190.10',
                changeOrigin: true,
                pathRewrite: {
                    '/api': ''
                }
            }
        },
        https: false
    },

    /**
     * Source Maps
     */
    productionSourceMap: false,
    configureWebpack: config => {

        let plugins = [
            new CompressionPlugin({
                algorithm: 'gzip',
                test: /\.(js|css)(\?.*)?$/i,//需要压缩的文件正则
                threshold: 1024,
                minRatio: 0.8,
                deleteOriginalAssets: false//压缩后保留原文件
            }),
        ]
        if (process.env.NODE_ENV === "production") {
            // 为生产环境修改配置...
            config.mode = "production";

        } else {
            // 为开发环境修改配置...
            config.mode = "development";
            //plugins.push(new BundleAnalyzerPlugin())
        }
        config.plugins = [...config.plugins, ...plugins]
        config.resolve = {
            alias: {
                '@': resolve('src')
            }
        }
        config.externals={

        }
    },

    chainWebpack: config => {
        config
            .plugin('html')
            .tap(args => {
                args[0].title= defaultSettings.title||"哈密市消防三维动态感知平台"
                return args
            })
    }


}
